/************** init.html **************/
function query_invBusiness(page) {
	sys_loading();
	var parm = $('#queryInvBusinessForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('invBusiness-query');
	sys_record_parm('invBusiness',parm);
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#invBusinessResultList').html(result);
		}
	});
}

/**
 * 验证Email地址
 * @param {} email
 * @return {Boolean}
 */
function validateEmail_invBusiness(obj) {
	var v = obj.val();
	if(/^([A-Za-z0-9])(\w)+@(\w)+(\.)(com|com\.cn|net|cn|net\.cn|org|biz|info|gov|gov\.cn|edu|edu\.cn)/.test(v)) {
	}else {
		sys_msg('邮箱格式不对哦！');
	}
	obj.css('border-color','');
}

//检查数量输入只能是数字
function checkNum_invBusiness(obj) {
	var v = obj.val();
	if (/^[1-9][0-9]*$/.test(v)) {
	} else {
		sys_msg('只能填数字,而且不能以0开头哦！');
		obj.val('');
	}
	obj.css('border-color','');
}

function save_invBusiness() {
	var parm = $('#editForm').serialize();
	var url = create_url('invBusiness-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功!');
				sys_load_handle('invBusiness');
			} else if (result == 'parameter_error'){
				sys_msg('联系人的电话和QQ都必须填哦!');
			} else if (result == 'exists'){
				sys_msg('单位所属类别必须填哦！');
			}else if (result == 'error'){
				sys_msg('操作失败!');
			}
		}
	});
}

function shield_invBusiness(code, name) {
	$.Zebra_Dialog('确定屏蔽吗？',{
	'type': 'question',
	'title': '警告' ,
	'buttons':[
       {caption:'屏蔽',callback:function() {
    	   var url = create_url('invBusiness-shield');
    	   aidExecute_invBusiness(code, url);
		}},
       {caption:'取消',callback:function(){}
       }]
	});
}

function unshield_invBusiness(code, name) {
	$.Zebra_Dialog('确定要解除屏蔽吗？',{
	'type': 'question',
	'title': '警告' ,
	'buttons':[
       {caption:'解除',callback:function() {
    	   var url = create_url('invBusiness-unshield');
    	   aidExecute_invBusiness(code, url);
		}},
       {caption:'取消',callback:function(){}
       }]
	});
}
function aidExecute_invBusiness(code, url) {
	var parm = {'code':code};
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if ('success' == result) {
				query_InvBusiness();
			} else {
				$.Zebra_Dialog('操作失败，请刷新页面再次尝试，如果问题依然存在，请联系管理员!');
			}
		}
	});
}

function selectOrgan_invBusiness() {
	var url = create_url('invBusiness-aidInit');
	var parm = {'id':'oc', 'name':'on'};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'800px', height:'600px', open:true});
}
//查询类型
function aidQuery_invBusiness(page) {
	sys_loading();
	var parm = $('#aidQueryForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('invBusiness-aidList1');
	$.ajax({type:'POST', url:url, data:parm,success: function(result) {
			sys_loading_close();
			$('#aidResultList').html(result);
			}
		});
	}
function selectType_invBusiness() {
	var url = create_url('invBusiness-aidInit1');
	var parm = {'id':'stc', 'name':'stn'};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'900px', height:'700px', open:true, 
			onClosed:function(){
			}
		});
	}

//选择
function choose_invBusiness(code, name) {
	$('#stc').val(code);
	$('#stn').val(name);
	$.fn.colorbox.close();
}


//添加空白行
function add_invBusiness() {
	var tr = $('#tempTable').find('tr').clone(true);
	var i = $('#index').val();
	tr.find('.name').attr('name', 'itemList[' + i + '].name').end()
	.find('.phone').attr('name', 'itemList[' + i + '].phone').end()
	.find('.qq').attr('name', 'itemList[' + i + '].qq').end()
	.find('.dc').attr({'name': 'itemList[' + i + '].dc'}).end();
	
	$('#ListBody').append(tr);
	$('#index').val(parseInt(i) + 1);
}


function delete_invBusiness(btn) {
	btn.parents('.rep').remove();
}


function check1_invBusiness(obj){
	var checks =$('#ListBody').find('input.dc');
	if(obj.attr('checked') || 'checked' == obj.attr('checked')){
		checks.each(function(e) {
			$(this).removeAttr('checked');
		});
		obj.attr('checked',true);
	}
}
function check2_invBusiness(obj){
	var checks =$('#editForm').find('input.box');
	if(obj.attr('checked') || 'checked' == obj.attr('checked')){
		checks.each(function(e) {
			$(this).removeAttr('checked');
		});
		obj.attr('checked',true);
	}
}